#include "dialogconfig.h"
#include "ui_dialogconfig.h"
#include <QSettings>
#include <QDebug>
#include <QMessageBox>
#include <QIntValidator>

DialogConfig::DialogConfig(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DialogConfig)
{
    ui->setupUi(this);

    setWindowFlags(windowFlags()& ~Qt::WindowMaximizeButtonHint);

    QValidator *validator=new QIntValidator(0,65535);
    ui->lineEditListenPort->setValidator(validator);

    //载入程序配置
    config.getConfigs();

    ui->lineEditListenPort->setText(QString::number(config.serverPort));
}

DialogConfig::~DialogConfig()
{
    delete ui;
}

void DialogConfig::on_cancelButton_clicked()
{
    close();
}

void DialogConfig::on_okButton_clicked()
{
    //获取组建输入
    int ServerPort = ui->lineEditListenPort->text().toInt();
    if(ServerPort <=0)
    {
        QMessageBox::critical(this, "错误", "请正确设置监听端口");
        return ;
    }

    //写入程序配置
    config.getConfigs();
    config.serverPort = ServerPort;
    config.setConfigs();

    //提示
    QMessageBox::warning(this, "提示", "修改后的配置将在程序下次启动时生效");

    close();
}
